package com.example.app2024.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import com.example.app2024.R;

import java.util.ArrayList;

public class FragmentDemoActivity extends AppCompatActivity
{
      private TextView textView;
      private ListView listView;
      private ArrayAdapter<String> adapter;
      String[] name = {"aa", "bb", "cc" , "dd" , "ee"};
      String[] content = {"AA"  , "BB" , "CC" , "DD" , "EE"};
      FragmentManager manager;

      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
            super.onCreate(savedInstanceState);
            EdgeToEdge.enable(this);
            setContentView(R.layout.activity_fragment_demo);
            ViewCompat.setOnApplyWindowInsetsListener(
                    findViewById(R.id.main), (v, insets) -> {
                          Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
                          v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
                          return insets;
                    });

            textView = findViewById(R.id.tv_fr01);
            listView = findViewById(R.id.lv_fr01);

            manager = getSupportFragmentManager();
            Fragment fragment = manager.findFragmentById(R.id.ffffff111);
            TextView st = fragment.getView().findViewById(R.id.sf001);


            adapter = new ArrayAdapter<>(this, R.layout.fragment_static_item  , name);
            listView.setAdapter(adapter);
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
            {
                  @Override
                  public void onItemClick(AdapterView<?> parent, View view, int position, long id)
                  {
                        st.setText(content[position]);
                  }
            });



      }
}